//商品模型

const { Model, DataTypes } = require("sequelize");

class Product extends Model {}

Product.init(
  {
    id: {
      type: DataTypes.INTEGER.UNSIGNED,
      primaryKey: true,
      autoIncrement: true,
      allowNull: false,
      comment: "表id",
    },

    productId: {
      type: DataTypes.STRING(36),
      unique: true,
      allowNull: false,
      defaultValue: "",
      comment: "商品id",
    },

    name: {
      type: DataTypes.STRING(30),
      allowNull: false,
      unique: true,
      defaultValue: "",
      comment: "书籍名称",
    },

    date: {
      type: DataTypes.STRING(50),
      allowNull: false,
      defaultValue: "",
      comment: "日期",
    },

    price: {
      type: DataTypes.DECIMAL(10, 2).UNSIGNED,
      allowNull: false,
      defaultValue: 0,
      comment: "书籍价格",
    },

    number: {
      type: DataTypes.STRING(30),
      allowNull: false,
      defaultValue: "",
      comment: "书籍编号",
    },

    publisher: {
      type: DataTypes.STRING(30),
      allowNull: false,
      defaultValue: "",
      comment: "出版人",
    },
    
    resource: {
      type: DataTypes.BOOLEAN,
      allowNull: false,
      defaultValue: 1,
      comment: "书籍状态0上架1下架",
    },

    smallImg: {
      type: DataTypes.STRING(100),
      allowNull: false,
      defaultValue: "",
      comment: "书籍图片",
    },

    largeImg: {
      type: DataTypes.STRING(100),
      allowNull: false,
      defaultValue: "",
      comment: "详情图片",
    },

    desc: {
      type: DataTypes.STRING(250),
      allowNull: true,
      defaultValue: null,
      comment: "书籍描述",
    },
  },
  {
    sequelize,
    tableName: "product",
  }
);

Product.sync({
  force: false,
});

module.exports = Product;
